package com.noticiasfi;

import java.net.URL;
import java.util.List;
import java.util.Vector;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MenuPrincipal extends ListActivity {
	String edittext,spinnvalor, miusuario, idagente;
	SAXParserFactory spf;
	SAXParser sp;
	XMLReader xr ;
	String[] arrayagre;
	private LayoutInflater mInflater;
	private Vector<RowData> data;
	@Override
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menuprincipal);

		mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
	        data = new Vector<RowData>();
			RowData rd = new RowData("","V Congreso Nacional de la Academia de Ingeniería");
	        data.add(rd);
	    	RowData rd1 = new RowData("","Reclutamiento Bain & Company");
	        data.add(rd1);
	       	RowData rd2 = new RowData("","Presentación de la Tuna de la Facultad de Ingeniería");
	        data.add(rd2);
	       	RowData rd3 = new RowData("","Cambio de mesa directiva de la SOMIM");
	        data.add(rd3);
	       	RowData rd4 = new RowData("","CONVOCATORIA DE INVESTIGACIÓN CIENTÍFICA BÁSICA 2012");
	        data.add(rd4);
	       	RowData rd5 = new RowData("","Obtención de la Matriz de cambio de base");
	        data.add(rd5);
	       
	        CustomAdapter adapter = new CustomAdapter(this, R.layout.custom_row2,R.id.item, data);
	        setListAdapter(adapter);
	}
	
	private class RowData {
	    protected String mItem;
	        protected String mDescription;
	        RowData(String item, String description){
	        mItem = item;
	        mDescription = description;             
	    }
	}
	
	private class CustomAdapter extends ArrayAdapter<RowData> {
	            public CustomAdapter(Context context, int resource,
	                int textViewResourceId, List<RowData> objects) {
	            	super(context, resource, textViewResourceId, objects);
	            	}

	            public View getView(int position, View convertView, ViewGroup parent) {
	                ViewHolder holder = null;
	                //widgets displayed by each item in your list
	                ImageView description = null; 
	                TextView item = null;
	                //data from your adapter
	                RowData rowData= getItem(position);
	                //we want to reuse already constructed row views...
	                if(null == convertView){
	                        convertView = mInflater.inflate(R.layout.custom_row2, null);
	                        holder = new ViewHolder(convertView);
	                        convertView.setTag(holder);
	                }
	                // 
	                holder = (ViewHolder) convertView.getTag();
	                item = holder.getDescription();
	                item.setText(rowData.mDescription);
	                item.setTextSize(18);
	    			item.setTextColor(Color.BLACK);
	                description = holder.getItem();  
	                return convertView;
	        }
    	}
		
	private class ViewHolder {      
		private View mRow;
		private ImageView item = null;
		private TextView description = null;
        public ViewHolder(View row) {
        	mRow = row;
        }
        public ImageView getItem() {
                if(null == item){
                        item = (ImageView) mRow.findViewById(R.id.descripcion);
                }
                return item;
        }
        public TextView getDescription() {
            if(null == description){
                    description = (TextView) mRow.findViewById(R.id.item);
            }
            return description;
        }
	}

	@Override
	protected void onListItemClick(ListView l, View v, final int position, long id) {
		switch(position){
		case 0:
				Intent in2 = new Intent(MenuPrincipal.this, Informacion.class);
		   		startActivity(in2);
		   		break;
		case 1:
		   		break;
		}
	}

			public boolean onCreateOptionsMenu(Menu menu) {
			    super.onCreateOptionsMenu(menu);
			    MenuInflater inflater = getMenuInflater();
			    inflater.inflate(R.menu.menuopciones, menu);
			    return true;
			}
	
		@Override
		public boolean onOptionsItemSelected(MenuItem item) {
			switch(item.getItemId()){
					case R.id.inicio:
						break;
					case R.id.categorias:
						Intent in = new Intent(MenuPrincipal.this, Categorias.class);
						startActivity(in);
						break;
					case R.id.mapa:
						Intent in2 = new Intent(MenuPrincipal.this, Mapa.class);
						startActivity(in2);
						break;
					case R.id.buscar:
						Intent in3 = new Intent(MenuPrincipal.this, Buscar.class);
						startActivity(in3);
						break;
			}
			return super.onOptionsItemSelected(item);
		}
		
		@Override
		public void onBackPressed() {
		}
}